package com.drg.center.controller;

import com.drg.center.entity.param.*;
import com.drg.center.entity.result.*;
import com.drg.center.service.MedicalSettleService;
import com.drg.center.service.StatisticsDoctorFromEsService;
import com.guaike.core.entity.result.PageEntity;
import com.guaike.core.entity.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;


@Slf4j
@RestController
@RequestMapping("/medicalSettle")
@Api(tags = "医保结算审核接口组")
@AllArgsConstructor
public class MedicalSettleController {

    private final MedicalSettleService medicalSettleService;
    private final StatisticsDoctorFromEsService statisticsDoctorFromEsService;

    @GetMapping("/count")
    @ApiOperation(value = "医保结算审核")
    public Result<MedicalSettleVO> medicalSettle(@Valid MedicalSettleDTO param) {
        return medicalSettleService.medicalSettle(param);
    }

    @GetMapping("/page")
    @ApiOperation(value = "医保结算审核列表")
    public Result<PageEntity<MedicalSettlePageVO>> medicalSettlePage(@Valid MedicalSettlePageDTO param) {
        return medicalSettleService.medicalSettlePage(param);
    }

    @GetMapping("/exportExcel")
    @ApiOperation(value = "导出excel")
    public void exportExcel(HttpServletResponse response, MedicalSettlePageDTO param) throws Exception {
        medicalSettleService.exportExcel(response, param);
    }

    @PostMapping("/noneUpload")
    @ApiOperation(value = "0000组上传")
    public Result<Boolean> noneUpload(@Valid @RequestBody NoneUploadDTO param) {
        return medicalSettleService.noneUpload(param);
    }

    @GetMapping("/diagnosisAndOperation")
    @ApiOperation(value = "医保结算审核诊断手术对照")
    public Result<MedicalSettleDetailVO> diagnosisAndOperation(@ApiParam("病例编码") @RequestParam("caseCode") String caseCode) {
        return medicalSettleService.diagnosisAndOperation(caseCode);
    }

    @PostMapping("/diagnosisAndOperationSave")
    @ApiOperation(value = "保存诊断手术")
    public Result<Boolean> diagnosisAndOperationSave(@Valid @RequestBody MedicalSettleDetailDTO param) {
        return medicalSettleService.diagnosisAndOperationSave(param);
    }

    @GetMapping("/groupPrediction")
    @ApiOperation(value = "分组预测")
    public Result<GroupPredictionVO> groupPrediction(@Valid MedicalSettleGroupPredictionDTO param) {
        return medicalSettleService.groupPrediction(param);
    }

    @GetMapping("/drgSettleStat")
    @ApiOperation(value = "DRG结算统计")
    public Result<List<DrgSettleVO>> drgSettleStat(SettleDateDTO param) {
        return Result.success().data(statisticsDoctorFromEsService.getDrgSettleStt(param.getSettleStartDate(), param.getSettleEndDate())).build();
    }

    @GetMapping("/drgSettleStatExportExcel")
    @ApiOperation(value = "DRG结算统计导出excel")
    public void drgSettleStatExportExcel(HttpServletResponse response, SettleDateDTO param) throws Exception {
        medicalSettleService.drgSettleStatExportExcel(response, param);
    }

    @GetMapping("/checkDrgPage")
    @ApiOperation(value = "校对结果查询")
    public Result<PageEntity<CaseMonitorOutCheckVO>> checkDrgPage(CaseCheckPageDTO param) {
        return medicalSettleService.checkDrgPage(param);
    }

    @GetMapping("/checkDrgDetail")
    @ApiOperation(value = "校对详情")
    public Result<CaseDrgCheckVO> checkDrgDetail(@ApiParam("病例编码") @RequestParam("caseCode") String caseCode) {
        return medicalSettleService.checkDrgDetail(caseCode);
    }
}
